package com.itheima.zuoye.zuoye6;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 创建集合，存入手机对象
        List<Phone> list = new ArrayList<>();
        list.add(new Phone("华为Mate50Pro", 6739.00));
        list.add(new Phone("vivoXFold2", 8999.00));
        list.add(new Phone("iphone14128G", 5999.00));
        list.add(new Phone("vivoiQOO11", 4399.00));
        list.add(new Phone("荣耀905G", 2799.00));
        list.add(new Phone("红米K60E", 1999.00));
        list.add(new Phone("华为nove11", 2799.00));
        list.add(new Phone("小米135G", 4299.00));


        while (true) {
            System.out.println("请输入您想购买的名称：");
            String brand = sc.next();
            // 遍历集合，找到那个手机
            // 【此处补充代码】！！！
            Phone phone = null;
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getBrand().equals(brand)) {
                    phone = list.get(i);
                    break;
                }
            }


            // 判断是否有这个手机
            if (phone== null) {
                System.out.println("输入的手机未找到。");
                continue;
            }

            // 定义钢化膜价格
            // 【此处补充代码】！！！
            BigDecimal glassPrice = BigDecimal.valueOf(10);

            System.out.println("请输入优惠方案：\n\t1-满3000打98折 \n\t2-以旧换新立减500");
            int choose = sc.nextInt();
            // 计算手机和钢化膜总价
            // 【此处补充代码】！！！
            BigDecimal total = BigDecimal.valueOf(phone.getPrice()).add(glassPrice);


            // 判断选择哪种方案
            switch (choose) {
                case 1:
                    if (total.compareTo(BigDecimal.valueOf(3000)) > 0) {
                        total = total.multiply(BigDecimal.valueOf(0.98));

                        System.out.println("您购买的手机是：" + phone.getBrand() + "，总价为：" + total);
                        break;
                    }

                case 2:
                    if (total.compareTo(BigDecimal.valueOf(500)) > 0) {
                        total = total.subtract(BigDecimal.valueOf(500));

                    System.out.println("您购买的手机是：" + phone.getBrand() + "，总价为：" + total);
                    break;}
            }
            // 【此处补充代码】！！！

        }
    }
}
